<%var jstpl = {%>

<script>
$(function(){

$("#resetpwd").click(function(){
	 gx.confirm("您是否确认将这个用户的密码初始化为：123456 ?",function(){
		gx.ajax("/system/role/user/resetpass/${admin.id!}",function(d){
			if(d.state==true){
				gx.toast("密码初始化成功！");
			}else{
				gx.alert("密码初始化成功！");
			}
		})
	 })
 })
 
$("#deluser").click(function(){
	 gx.confirm("您是否确定删除这个用户？",function(){
			gx.ajax("/system/role/user/delete/${admin.id!}",function(d){
				if(d.state==true){
					gx.toast("用户删除成功！",function(){
						window.location.replace("/system/role/user");	
					})
				}else{
					alert(d.msg)
				}
			})
		 })
	 
 })
 
})

var form = layui.form;
form.verify({
	atleastone:function(value,item){
		if($("input[name='admin.role_id']:checked").length<=0){
			return "请至少选择一个权限组";
		}
	}
})

	form.verify({
		checkUserName:function(value,item){
			var isRepeat = false;
			$.ajax({
				  url: "/system/role/user/checkname?value="+value,
				  async: false,
				  success:function(d){
					  if(d.state==true){ 
						  isRepeat =true;
					   }	 	
					}
				 })
				 
			if(isRepeat){
				return '用户名已存在!';
			}
		} 	
	})


</script>

<%};%>

<%var csstpl = {%>

<%};%>

<%var title={%>
添加/修改管理员  
  <%if(admin!null!=null){%>
  <a class="layui-badge layui-bg-blue" id="resetpwd" href="javascript:;"><i class="icol-magnifier"></i>重置密码</a>
  <a class="layui-badge" id="deluser" href="javascript:;"><i class="icol-cross"></i>删除用户</a>
      <%}%>
<%};%>
<%layout("../layout/_layout_layui.html",{title:title,jstpl:jstpl,csstpl:csstpl}){ %>
	<section id="content">
	 <form  method="post" id="add_validate" action="/system/role/user/save" class="layui-form  form-horizontal"  role="form">
       <input type="hidden" name="admin.id" value="${admin.id!}">
       <div class="layui-row">
   <%if(admin!null!=null){%>
          
             <div class="layui-form-item ">
                 <label class="layui-form-label">用户名</label>
                  
                 <div class="layui-input-inline ">
                     <input type="text"  readonly="readonly"  required  lay-verify="required"   name="admin.username" value="${admin.username!}"  class="layui-input" placeholder="">
                 </div>
                   <div class="layui-form-mid layui-word-aux">用户名不可以修改</div>
             </div>
         
         <%}else{%>
           
             <div class="layui-form-item ">
               <label class="layui-form-label">用户名</label>
                 <div class="layui-input-inline ">
                     <input type="text" class="layui-input"  required  lay-verify="required|checkUserName"   name="admin.username" value="" >
                 </div>
             </div>
         
             <div class="layui-form-item ">
                    <label class="layui-form-label">用户密码</label>
                 <div class="layui-input-inline ">
                     <input type="password" class="layui-input" required  lay-verify="required"  data-rule="required;password"  name="admin.password" value="${admin.password!}"  id="password">
                
                 </div>
         </div>
       <%}%>
         </div>
      <div class="layui-row clearfix ">
     
             <div class="layui-form-item">
                    <label class="layui-form-label">真实姓名</label>
                 <div class="layui-input-inline ">
                     <input type="text" class="layui-input" name="admin.name" lay-verify="required"  value="${admin.name!}"  id="name">
                 </div>
         </div>
         
    
             <div class="layui-form-item ">
             <label class="layui-form-label">移动电话</label>
                 <div class="layui-input-inline ">
                     <input type="text" class="layui-input " name="admin.tel" lay-verify="required|phone"   value="${admin.tel!}"  id="tel" >
                       
                 </div>
         </div>
         
            
             <div class="layui-form-item ">
             <label class="layui-form-label">邮箱地址</label>
                 <div class="layui-input-inline ">
                     <input type="text" class="layui-input"  name="admin.email" lay-verify="required|email"  value="${admin.email!}" id="email" >
                       
                 </div>
         </div>
         
            
             
			<div class="layui-form-item" lay-verify="atleastone" >
				<label class="layui-form-label">用户权限组</label>
				<div class="layui-input-block">
				<%for(var role in rolelist!){%>
					<input type="checkbox" value="${role.id}"  ${array.contain(roleIds,role.id)?'checked':''}   name="admin.role_id" title="${role.name}">
				<% } %>
					
				</div>
			</div>
			<div class="layui-form-item ">
             <label class="layui-form-label">用户状态</label>
               <div class="layui-input-inline">
                     
                       <input type="checkbox" ${admin.state!0==0?'checked':''}  value="0"   name="admin.state" lay-skin="switch" lay-text="启用|禁用">
                </div>                    
         </div>
         
         <div class="layui-form-item">
			 <div class="layui-input-block">
			 <button  lay-submit lay-filter="formDemo" class="layui-btn"><i class=""></i>保存</button>
			  <button onclick="window.history.back()" type="button" class="layui-btn layui-btn-primary"><i class="zmdi zmdi-close"></i>返回</button>
			 </div>
		</div>
       </div>
    
               <!--  内容结束 -->
          </form>
     </section>

<%}%>